function brandTitleJs() {
    let categoryBox = document.getElementById("category-list")
        //
    function renderCategory(rankData) {
        ajax({
            url: "http://chst.vip:1234/api/getbrandtitle?key=all",
            success(res) {
                let caData = res.result;
                let html = ""
                caData.forEach(item => {
                    html += ` 
                <div id="cate">${item.brandTitle} <span>▼</span></div>
                <section id="ranking">
                </section>`
                });
                categoryBox.innerHTML = html
                let cates = document.querySelectorAll('#cate')
                let ranks = document.querySelectorAll('#ranking')
                for (let i = 0; i < cates.length; i++) {
                    request2(caData[i].brandTitleId, ranks[i])
                }
                // 开关效果
                for (let j = 0; j < cates.length; j++) {
                    let flag = true;
                    cates[j].onclick = () => {
                        console.log(cates[j]);
                        console.log(ranks[j]);
                        if (flag) {
                            ranks[j].style.display = "block"
                            flag = !flag
                        } else {
                            ranks[j].style.display = "none"
                            flag = !flag
                        }
                        let rankS = ranks[j].children;
                        for (let i = 0; i < rankS.length; i++) {
                            rankS[i].onclick = () => {
                                // console.log(rankS[i]);
                                ajax({
                                    url: "http://chst.vip:1234/api/getbrand",
                                    data: {
                                        brandtitleid: caData[i].brandTitleId
                                    },
                                    success(res) {
                                        let num = j * 10 + i
                                        location.href = `brand.html?brandtitleid=${num}&brandName=${res.result[i].brandName}&categoryId=${res.result[i].categoryId}`
                                        console.log(num);
                                        // console.log(res.result[i]);
                                        // console.log(res.result[j * 10 + i].brandName);
                                        console.log(rankS[i]);
                                    }
                                })
                            }
                        }

                    }
                }
            }
        })
    }

    renderCategory()

    function request2(brandtitleid, rank) {
        ajax({
            url: "http://chst.vip:1234/api/getbrand",
            data: {
                brandtitleid: brandtitleid
            },
            success(res) {
                let html = ""
                let num = 0;
                let rankData = res.result
                rankData.forEach(item => {
                    num++
                    html += `<a>
                <div>
                <span>${num}</span>
                <span>${item.brandName}</span>
                </div>
                <span>${item.brandInfo}</span>
                </a>`
                })
                rank.innerHTML = html
            }
        })
    }
    // 返回顶部按钮功能实现
    document.querySelector('#main').onscroll = function() {
        top0.onclick = function() {
            document.querySelector('#main').scrollTop = 0
        }
    }
}
brandTitleJs()